import 'dart:async';

import 'package:enterprise_v6_app/app/components/custom_app_bar.dart';
import 'package:enterprise_v6_app/app/core/utils/location_util.dart';
import 'package:flutter/material.dart';

class LocationTestPage extends StatefulWidget {
  const LocationTestPage({super.key});

  @override
  State<LocationTestPage> createState() => _LocationTestPageState();
}

class _LocationTestPageState extends State<LocationTestPage> {

  // 每隔1秒刷新一次页面
  Timer? timer;

  //  每隔1秒刷新一次页面
  void _refTime() {
    timer = Timer.periodic(const Duration(seconds: 1), (timer) {
      setState(() {});
    });
  }

  @override
  void initState() {
    super.initState();
    _refTime();
  }

  @override
  Widget build(BuildContext context) {
    return Scaffold(
        appBar: CustomAppBar(
          title: const Text('定位测试'),
        ),
        body: ListView.builder(
          itemCount: LocationUtil.positions.length,
          reverse: true,
          itemBuilder: (context, index) {
            return ListTile(
              visualDensity: VisualDensity.compact,
              title: Text('$index-经纬度：${LocationUtil.positions[index]['longitude']}-${LocationUtil.positions[index]['latitude']}-高度:${LocationUtil.positions[index]['altitude']}'),
              subtitle: Text('${LocationUtil.positions[index]['locationTime']}'),
            );
          },
        ));
  }

  @override
  void dispose() {
    timer?.cancel();
    super.dispose();
  }
}
